package com.qf.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.pojo.DtsCategory;
import com.qf.service.DtsCategoryService;
import com.qf.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/admin/category")
public class DtsAdminCategoryController {

    @Autowired
    DtsCategoryService categoryService;

    @PostMapping("delete")
    public Object delete(@RequestBody DtsCategory category){
        categoryService.delete(category);
        return ResponseUtil.ok();
    }

    @PostMapping("/update")
    public Object update(@RequestBody DtsCategory category){
        categoryService.update(category);
        return ResponseUtil.ok();
    }

    @PostMapping("/create")
    public Object create(@RequestBody DtsCategory category){
        DtsCategory category1 = categoryService.insert(category);
        return ResponseUtil.ok(category1);
    }

    @GetMapping("/l1")
    public Object l1(){
        List<Map<String,Object>> l1 = categoryService.queryL1();
        return ResponseUtil.ok(l1);
    }
    @GetMapping("/list")
    public Object list(@RequestParam(value = "page",required = false,defaultValue = "1") Integer page,
                       @RequestParam(value = "limit",required = false,defaultValue = "10") Integer limit,
                       String sort, String order, Integer id, String name){
        IPage<DtsCategory> iPage = categoryService.queryPage(page,limit,sort,order,id,name);

        Map<String,Object> data = new HashMap<>();
        data.put("total",iPage.getTotal());
        data.put("items",iPage.getRecords());
        return ResponseUtil.ok(data);
    }
}
